package com.changgou.order.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/cart")
public class CartController {
  @Autowired
  private CartService cartService;

  @GetMapping("/addCart")
  public Result addCart(@RequestParam("skuId") String skuId, @RequestParam("num") Integer num) {
    //登录人的姓名,后端来获取
//    动态获取登录人的姓名
    String username="itjava";
    cartService.addCart(skuId,num,username);
    return new Result(true, StatusCode.OK,"加入购物车成功");
  }

  @GetMapping("/addCart")
  public Map addCart() {
    //登录人的姓名,后端来获取
//    动态获取登录人的姓名
    String username="itjava";
    Map map = cartService.list(username);
    return map;
  }
}
